package com.dormitory_springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dormitory_springboot.bean.Admin;
import com.dormitory_springboot.bean.Homemaster;
import com.dormitory_springboot.form.RuleForm;
import com.dormitory_springboot.mapper.HomemasterMapper;
import com.dormitory_springboot.service.HomemasterService;
import com.dormitory_springboot.utils.JWTutil;
import com.dormitory_springboot.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @auther 夏杨
 **/
@Service
public class HomemasterServiceImpl extends ServiceImpl<HomemasterMapper, Homemaster> implements HomemasterService {
    @Autowired
    HomemasterMapper homemasterMapper;
    @Override
    public ResultVO login(RuleForm ruleForm) {
        Homemaster homemaster = homemasterMapper.selectById(ruleForm.getId());
        ResultVO resultVO = new ResultVO();
        if(homemaster == null)
            resultVO.setCode(-1);
        else if(!homemaster.getPassword().equals(ruleForm.getPass())){
            resultVO.setCode(-2);
        }else {
            resultVO.setCode(0);
            resultVO.setData(homemaster);
            resultVO.setToken(JWTutil.creatJWTByHomemaster(homemaster));
        }
        return resultVO;
    }
}
